package com.hsj.busmanager.service;

import com.hsj.busmanager.api.Bus;
import com.hsj.busmanager.api.CostType;
import com.hsj.busmanager.mapper.CostTypeMapper;
import com.hsj.busmanager.util.CommonUtil;
import com.hsj.busmanager.util.Page;
import com.hsj.busmanager.util.TabelData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CostTypeSerivce {

    @Autowired
    private CostTypeMapper costTypeMapper;

    public TabelData<CostType> getCostTypePage(Page page, CostType costType) {

        TabelData tabelData = new TabelData();

        Integer start = (page.getPage()-1)*page.getLimit();

        List<CostType> costTypeList = costTypeMapper.getCostTypePage(start,page.getLimit(),costType);

        int count = costTypeMapper.getCostTypeCount(costType);

        if (costTypeList == null && costTypeList.size() == 0) {
            return null;
        }

        tabelData.setCount(count);
        tabelData.setData(costTypeList);

        return tabelData;

    }

    public void deleteByCostName(String costName) {
        costTypeMapper.deleteByCostName(costName);
    }

    public CostType getCostTypeByCostName(String costName) {
        return costTypeMapper.selectByPrimaryKey(costName);
    }

    public void update(CostType costType) {
        costTypeMapper.updateByPrimaryKeySelective(costType);
    }

    public void insert(CostType costType) {
        costType.setUsed(1);
        costTypeMapper.insert(costType);
    }
}
